package com.puti.doctor.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.puti.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.puti.common.log.annotation.Log;
import com.puti.common.log.enums.BusinessType;
import com.puti.common.security.annotation.PreAuthorize;
import com.puti.doctor.domain.SystemHospitalDept;
import com.puti.doctor.service.ISystemHospitalDeptService;
import com.puti.common.core.web.controller.BaseController;
import com.puti.common.core.web.domain.AjaxResult;
import com.puti.common.core.utils.poi.ExcelUtil;
import com.puti.common.core.web.page.TableDataInfo;

/**
 * 系统管理-医院-科室 系统管理-医院-科室Controller
 * 
 * @author puti
 * @date 2021-04-26
 */
@CrossOrigin
@RestController
@RequestMapping("/dept")
public class SystemHospitalDeptController extends BaseController
{
    @Autowired
    private ISystemHospitalDeptService systemHospitalDeptService;

    /**
     * 查询系统管理-医院-科室 系统管理-医院-科室列表
     */
    @PreAuthorize(hasPermi = "system:dept:list")
    @GetMapping("/list")
    public TableDataInfo list(SystemHospitalDept systemHospitalDept)
    {
        startPage();
        List<SystemHospitalDept> list = systemHospitalDeptService.selectSystemHospitalDeptList(systemHospitalDept);
        return getDataTable(list);
    }
    @GetMapping("/findByHospitalId/{deptHospitalId}")
    public R findByHospitalId(@PathVariable("deptHospitalId") Long deptHospitalId){
        return R.ok(systemHospitalDeptService.findByHospitalId(deptHospitalId),"查询成功");
    }
    /**
     * 导出系统管理-医院-科室 系统管理-医院-科室列表
     */
    @PreAuthorize(hasPermi = "system:dept:export")
    @Log(title = "系统管理-医院-科室 系统管理-医院-科室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SystemHospitalDept systemHospitalDept) throws IOException
    {
        List<SystemHospitalDept> list = systemHospitalDeptService.selectSystemHospitalDeptList(systemHospitalDept);
        ExcelUtil<SystemHospitalDept> util = new ExcelUtil<SystemHospitalDept>(SystemHospitalDept.class);
        util.exportExcel(response, list, "系统管理-医院-科室 系统管理-医院-科室数据");
    }

    /**
     * 获取系统管理-医院-科室 系统管理-医院-科室详细信息
     */
    @PreAuthorize(hasPermi = "system:dept:query")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(systemHospitalDeptService.selectSystemHospitalDeptById(deptId));
    }

    /**
     * 新增系统管理-医院-科室 系统管理-医院-科室
     */
    @PreAuthorize(hasPermi = "system:dept:add")
    @Log(title = "系统管理-医院-科室 系统管理-医院-科室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SystemHospitalDept systemHospitalDept)
    {
        return toAjax(systemHospitalDeptService.insertSystemHospitalDept(systemHospitalDept));
    }

    /**
     * 修改系统管理-医院-科室 系统管理-医院-科室
     */
    @PreAuthorize(hasPermi = "system:dept:edit")
    @Log(title = "系统管理-医院-科室 系统管理-医院-科室", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SystemHospitalDept systemHospitalDept)
    {
        return toAjax(systemHospitalDeptService.updateSystemHospitalDept(systemHospitalDept));
    }

    /**
     * 删除系统管理-医院-科室 系统管理-医院-科室
     */
    @PreAuthorize(hasPermi = "system:dept:remove")
    @Log(title = "系统管理-医院-科室 系统管理-医院-科室", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(systemHospitalDeptService.deleteSystemHospitalDeptByIds(deptIds));
    }
}
